package com.zr.inquiry.controller;

import com.zr.inquiry.model.*;
import com.zr.inquiry.service.InquiryService;
import com.zr.planclass.util.ResultBuilderVo;
import com.zr.planclass.util.ResultVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.*;


/**
 * Created by lenovo on 2019/12/27.
 */
@RestController
@CrossOrigin
public class InquiryController {
    @Autowired
    private InquiryService inquiryService;

  @PostMapping("inquiryList/search")
    public ResultVo inquiryList(@RequestBody InquiryServiceVo inquiryServiceVo){
        ResultVo resultVo = inquiryService.inquiryList(inquiryServiceVo);

        return resultVo;
    }

   /* @GetMapping("plan/getUser")
    public ResultVo getUser(){

        ResultVo resultVo = inquiryService.getUserDanHao();

        return resultVo;*/
    /*选择备件*/
    @PostMapping("inquiryList/selectMaterial")
    public ResultVo queryPage(@RequestBody MaterialSelectVo materialSelectVo){

        return inquiryService.queryPage(materialSelectVo);

    }

    /*选择供应商*///material/searchPartnerPage
    @PostMapping ("material/searchPartnerPage")
    public ResultVo searchPartnerPage(@RequestBody SupplierSelectVo supplierSelectVo){

        return inquiryService.searchPartnerPage(supplierSelectVo);

    }
   @GetMapping ("partner/queryByLegalPerson")
    public ResultVo queryByLegalPerson(Integer legalPersonId){

        return inquiryService.queryByLegalPerson(legalPersonId);

    }
    /*询价新增保存接口*/
    @PostMapping("inquiryList/add")
    public ResultVo add(@RequestBody InquiryAddVo inquiryAddVo, BindingResult bindingResult){
        if(bindingResult.hasErrors()){
            return ResultBuilderVo.error(bindingResult.getFieldError().getDefaultMessage());
        }
        return inquiryService.add(inquiryAddVo);
    }
    /*修改查看*/
    @PostMapping("inquirySheet/see")
    public ResultVo see(@RequestBody InquiryVo inquiryVo){
        return  inquiryService.see(inquiryVo.getRequestForQuotationId());
    }
    //修改
    @PostMapping("inquiryList/update")
    public ResultVo update(@RequestBody InquiryAddVo inquiryAddVo, BindingResult bindingResult){
        if (bindingResult.hasErrors()){
            return ResultBuilderVo.error(bindingResult.getFieldError().getDefaultMessage());
        }
        return inquiryService.update(inquiryAddVo);
    }


}
